package org.sippr.service.impl;

import org.sippr.mapper.WordCueMapper;
import org.sippr.pojo.WordCue;
import org.sippr.service.WordCueService;
import org.sippr.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class WordCueImpl implements WordCueService {
    @Autowired
    private WordCueMapper wordCueMapper;

    @Override
    public void add(WordCue value) {

        Map<String, Object> map = ThreadLocalUtil.get();
        String id = (String) map.get("id");
        value.setCreateUser(id);
        value.setUpdateUser(id);

        LocalDateTime time = LocalDateTime.now();
        value.setCreateTime(time);
        value.setUpdateTime(time);


        wordCueMapper.insert(value);
    }

    @Override
    public WordCue findByName(String chName) {
        return wordCueMapper.findByName(chName);
    }

    @Override
    public List<WordCue> findByClsId(Integer clsId) {
        return wordCueMapper.findByClsId(clsId);
    }

    @Override
    public void delete(Integer id) {
        wordCueMapper.deleteByPrimaryKey(id);
    }


}
